import 'dart:convert';
import 'dart:developer';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:get_storage/get_storage.dart';
import 'package:jxchmz/Getx%E5%B7%A5%E5%85%B7/GetxTools.dart';

class HexGo  {
  String ApiUrl = "http://192.168.31.86:8080";
  Dio dio = new Dio();
  var ResponseData;

  // 获取本地token
  configDio() async {
    // 获取本地token
    GetStorage storage = GetStorage();
    String Token =await storage.read("Token");
    print("token:$Token");
    print("账号:${await storage.read("Phone")}");
    print("密码:${await storage.read("Password")}");
    // 构造请求头
    dio.options.contentType="application/json";
    dio.options.headers['Authorization'] = "Bearer $Token";
    dio.options.connectTimeout = 5000;
    dio.options.receiveTimeout = 3000;
  }

  shiLiuGoZhong(Hex) async {
    // /system/appUtils/shiLiuGoZhong
    //配置dio
    await configDio();
    try{ ResponseData = await dio
        .get(ApiUrl + "/system/appUtils/shiLiuGoZhong",queryParameters: {"hexStr":Hex});
    if (ResponseData.statusCode == 200) {
      // 请求成功
      ResponseData =
          json.decode(ResponseData.toString());
      log("数据返回:$ResponseData");
      return ResponseData;
    } else {
      log("请求失败，状态码:${ResponseData.statusCode}");
      GetxTools().ErrorToast("系统异常");
      return "";
    }
    }catch(e){
      GetxTools().ErrorToast("系统异常");
      return "";
    }

  }

}
